#!/usr/bin/python2

import math

import pygame

from utils import Constants


class Level(pygame.sprite.Sprite):

    def __init__(self, x, y, lev, text, groups=tuple()):
        # Initialize parent
        pygame.sprite.Sprite.__init__(self, groups)
        # Set the image and bounds
        font = pygame.font.SysFont("Arial", 20)
        tw, th = font.size(text)
        w = math.ceil(tw * 1.0 / Constants.GRID_SIZE) * Constants.GRID_SIZE
        h = math.ceil(th * 1.0 / Constants.GRID_SIZE) * Constants.GRID_SIZE
        t = font.render(text, False, pygame.color.Color(Constants.FONT_COLOR2))
        self.image = pygame.surface.Surface((w, h), pygame.SRCALPHA)
        self.image.blit(t, ((w - tw) // 2, (h - th) // 2))
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
        self.__level = lev
        self.__alive = True

    def alive(self):
        al = self.__alive
        self.__alive = True
        return al

    def kill(self):
        self.__alive = False

    def update(self, delta, rotation, groups):
        pass

    def which(self):
        return self.__level
